package org.example.medical.controller;

import org.example.medical.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/dashboard")
public class DashboardApiController {
    @Autowired
    private DashboardService dashboardService;

    @GetMapping("/data")
    public Map<String, Object> dashboardData() {
        Map<String, Object> response = new HashMap<>();

        // 1. 人次占比数据
        response.put("visitData", dashboardService.getVisitData());

        // 2. 手术数量趋势数据
        response.put("surgeryTrend", dashboardService.getSurgeryTrend());

        // 3. 当月出院环比数据
        response.put("dischargeData", dashboardService.getDischargeData());

        // 4. 病症诊断人数数据
        response.put("diseaseData", dashboardService.getDiseaseData());

        // 5. 医疗耗材环比数据
        response.put("suppliesRatio", dashboardService.getSuppliesRatio());

        // 6. 数据共享表格数据
        response.put("sharedData", dashboardService.getSharedData());

        // 7. 年龄分布数据
        response.put("ageDistribution", dashboardService.getAgeDistribution());

        // 8. 人均医药费分布数据
        response.put("costDistribution", dashboardService.getCostDistribution());

        // 9. 付费方式分布数据
        response.put("paymentDistribution", dashboardService.getPaymentDistribution());

        return response;

//        Map<String, Object> response = new HashMap<>();
//
//        // 1. 人次占比数据
//        List<Map<String, Object>> visitData = new ArrayList<>();
//        visitData.add(Map.of("type", "门诊", "today", 356, "yesterday", 320, "proportion", 47));
//        visitData.add(Map.of("type", "急诊", "today", 185, "yesterday", 172, "proportion", 25));
//        visitData.add(Map.of("type", "体检", "today", 120, "yesterday", 105, "proportion", 16));
//        visitData.add(Map.of("type", "入院", "today", 89, "yesterday", 75, "proportion", 12));
//        response.put("visitData", visitData);
//
//        // 2. 手术数量趋势数据
//        Map<String, Object> surgeryTrend = new HashMap<>();
//        surgeryTrend.put("years", new String[]{"2020", "2021", "2022", "2023", "2024"});
//        surgeryTrend.put("Scheduled", new int[]{120, 135, 142, 156, 185});
//        surgeryTrend.put("Completed", new int[]{95, 105, 115, 140, 155});
//        surgeryTrend.put("Cancelled", new int[]{75, 85, 100, 110, 120});
//        response.put("surgeryTrend", surgeryTrend);
//
//        // 3. 当月出院环比数据
//        Map<String, Integer> dischargeData = new HashMap<>();
//        dischargeData.put("admission", 125);
//        dischargeData.put("discharge", 98);
//        dischargeData.put("retained", 27);
//        response.put("dischargeData", dischargeData);
//
//        // 4. 病症诊断人数数据
//        List<Map<String, Object>> diseaseData = new ArrayList<>();
//        String[] diseases = {"呼吸系统", "循环系统", "消化系统", "神经系统", "损伤中毒"};
//        int[] paid = {180, 145, 130, 110, 75};
//        int[] unpaid = {76, 44, 42, 24, 23};
//        for (int i = 0; i < diseases.length; i++) {
//            Map<String, Object> disease = new HashMap<>();
//            disease.put("name", diseases[i]);
//            disease.put("paid", paid[i]);
//            disease.put("unpaid", unpaid[i]);
//            diseaseData.add(disease);
//        }
//        response.put("diseaseData", diseaseData);
//
//        // 5. 医疗耗材环比数据
//        Map<String, Map<String, Integer>> suppliesRatio = new HashMap<>();
//        suppliesRatio.put("medical", Map.of("current", 85, "lastMonth", 72));
//        suppliesRatio.put("supplies", Map.of("current", 120, "lastMonth", 105));
//        response.put("suppliesRatio", suppliesRatio);
//
//        // 6. 数据共享表格数据
//        List<Map<String, Object>> sharedData = new ArrayList<>();
//        String[] hospitals = {"市一医院", "中心医院", "协和医院", "同仁医院", "华西医院"};
//        String[] departments = {"内科", "外科", "儿科", "妇产科", "骨科"};
//        int[] shares = {256, 198, 172, 145, 123};
//        for (int i = 0; i < hospitals.length; i++) {
//            sharedData.add(Map.of(
//                    "hospital", hospitals[i],
//                    "department", departments[i],
//                    "shared", shares[i]
//            ));
//        }
//        response.put("sharedData", sharedData);
//
//        // 7. 年龄分布数据
//        Map<String, Integer> ageDistribution = new HashMap<>();
//        ageDistribution.put("0-18岁", 15);
//        ageDistribution.put("19-35岁", 25);
//        ageDistribution.put("36-50岁", 30);
//        ageDistribution.put("51-65岁", 20);
//        ageDistribution.put("65岁以上", 10);
//        response.put("ageDistribution", ageDistribution);
//
//        // 8. 人均医药费分布数据
//        List<Map<String, Object>> costDistribution = new ArrayList<>();
//        costDistribution.add(Map.of("range", "0-500元", "count", 1200));
//        costDistribution.add(Map.of("range", "500-2000元", "count", 850));
//        costDistribution.add(Map.of("range", "2000-5000元", "count", 420));
//        costDistribution.add(Map.of("range", "5000-8000元", "count", 180));
//        costDistribution.add(Map.of("range", "8000元以上", "count", 75));
//        response.put("costDistribution", costDistribution);
//
//        // 9. 付费方式分布数据
//        Map<String, Integer> paymentDistribution = new HashMap<>();
//        paymentDistribution.put("支付宝", 35);
//        paymentDistribution.put("银行卡", 25);
//        paymentDistribution.put("医保卡", 30);
//        paymentDistribution.put("微信", 10);
//        response.put("paymentDistribution", paymentDistribution);
//
//        return response;
    }
}